/**
 * 
 * 起迪科技 Copyright (c) 2014-2018 QiDi,Inc.All Rights Reserved.
 */
package cn.qidisoft.edu.hzjt.service.impl;

import java.util.List;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.qidisoft.core.common.code.QdfRespCode;
import cn.qidisoft.core.common.exception.dao.DBException;
import cn.qidisoft.core.common.log.LoggerAdapter;
import cn.qidisoft.core.common.log.LoggerAdapterFactory;
import cn.qidisoft.core.common.pagination.Page;
import cn.qidisoft.core.common.pagination.PaginationBean;
import cn.qidisoft.edu.hzjt.dao.PartyJoinActivistMapper;
import cn.qidisoft.edu.hzjt.dao.PartyJoinDevelopmentAttMapper;
import cn.qidisoft.edu.hzjt.model.PartyJoinActivist;
import cn.qidisoft.edu.hzjt.service.IPartyJoinActivistService;
import cn.qidisoft.edu.hzjt.utils.LogType;

/**
 * 
 * 
 * @author hhl
 * @version $Id: PartyJoinActivistServiceImpl.java, v 0.1 2018年12月24日 下午2:14:02 hhl Exp $
 */
@Service("partyJoinActivistService")
public class PartyJoinActivistServiceImpl implements IPartyJoinActivistService {

    protected static final LoggerAdapter  LOGGER = LoggerAdapterFactory
        .getLogger(LogType.HZJT_LOGGER.val);

    @Autowired
    private PartyJoinActivistMapper       partyJoinActivistMapper;
    @Autowired
    private PartyJoinDevelopmentAttMapper partyJoinDevelopmentAttMapper;

    @Override
    public List<PartyJoinActivist> queryList(PartyJoinActivist data) {
        try {
            return partyJoinActivistMapper.queryList(data);
        } catch (Exception e) {
            LOGGER.error("queryList [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
    }

    @Override
    public PartyJoinActivist queryByPK(PartyJoinActivist data) {
        try {
            return partyJoinActivistMapper.queryByPK(data);
        } catch (Exception e) {
            LOGGER.error("queryByPK [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
    }

    @Override
    @Transactional
    public int add(PartyJoinActivist data) {
        try {
            return partyJoinActivistMapper.add(data);
        } catch (Exception e) {
            LOGGER.error("add [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
    }

    @Override
    @Transactional
    public int update(PartyJoinActivist data) {
        try {
            return partyJoinActivistMapper.update(data);
        } catch (Exception e) {
            LOGGER.error("update [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
    }

    @Override
    @Transactional
    public int delete(PartyJoinActivist data) {
        try {
            return partyJoinActivistMapper.delete(data);
        } catch (Exception e) {
            LOGGER.error("delete [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
    }

    @Override
    public PaginationBean<PartyJoinActivist> queryPageList(PartyJoinActivist data, Page page) {
        try {

            int c = partyJoinActivistMapper.queryPageListcount(data);
            int totalRecords = 0;
            totalRecords = (int) c;
            PaginationBean<PartyJoinActivist> pageHolder = new PaginationBean<PartyJoinActivist>(
                page, totalRecords);
            List<PartyJoinActivist> resultList = partyJoinActivistMapper.queryPageList(data,
                new RowBounds((pageHolder.getCurrentPage() - 1) * pageHolder.getPageSize(),
                    pageHolder.getPageSize()));
            pageHolder.setPageList(resultList);
            return pageHolder;
        } catch (Exception e) {
            LOGGER.error("queryPageList [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
    }

    @Override
    public int validation(PartyJoinActivist data) {
        try {
            return partyJoinActivistMapper.validation(data);
        } catch (Exception e) {
            e.printStackTrace();
            return -99;
        }
    }

    @Override
    public List<PartyJoinActivist> export(PartyJoinActivist data) {
        try {
            return partyJoinActivistMapper.export(data);
        } catch (Exception e) {
            LOGGER.error("export [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
    }
}
